const db = require('../utils/db');

const User = {
  create(username, password) {
    return new Promise((resolve, reject) => {
      db.run('INSERT INTO users (username, password) VALUES (?, ?)', [username, password], function(err) {
        if (err) reject(err);
        resolve(this.lastID);
      });
    });
  },
  findByUsername(username) {
    return new Promise((resolve, reject) => {
      db.get('SELECT * FROM users WHERE username = ?', [username], (err, row) => {
        if (err) reject(err);
        resolve(row);
      });
    });
  }
};

module.exports = User;

